home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb.new / gdb-4.0 / bfd / doc / bfd.info-3 < prev    next >
Encoding:
Text File  |  1991-09-29  |  14.8 KB  |  412 lines

  1. Info file bfd.info, produced by Makeinfo, -*- Text -*- from input
  2. file bfd.texinfo.
  3.  
  4.    This file documents the BFD library.
  5.  
  6.    Copyright (C) 1991 Free Software Foundation, Inc.
  7.  
  8.    Permission is granted to make and distribute verbatim copies of
  9. this manual provided the copyright notice and this permission notice
  10. are preserved on all copies.
  11.  
  12.    Permission is granted to copy and distribute modified versions of
  13. this manual under the conditions for verbatim copying, subject to the
  14. terms of the GNU General Public License, which includes the provision
  15. that the entire resulting derived work is distributed under the terms
  16. of a permission notice identical to this one.
  17.  
  18.    Permission is granted to copy and distribute translations of this
  19. manual into another language, under the above conditions for modified
  20. versions.
  21.  
  22.  
  23. 
  24. File: bfd.info,  Node: coff,  Next: Index,  Prev: BFD back end,  Up: Top
  25.  
  26. coff backends
  27. =============
  28.  
  29.    BFD supports a number of different flavours of coff format. The
  30. major difference between formats are the sizes and alignments of
  31. fields in structures on disk, and the occasional extra field.
  32.  
  33.    Coff in all its varieties is implimented with a few common files
  34. and a number of implementation specific files. For example, The 88k
  35. bcs coff format is implemented in the file `m88k-bcs.c'. This file
  36. `#include's `m88k-bcs.h' which defines the external structure of the
  37. coff format for the 88k, and `internalcoff.h' which defines the
  38. internal structure. `m88k-bcs.c' also defines the relocations used by
  39. the 88k format *Note Relocations::. Then the major portion of coff
  40. code is included (`coffcode.h') which defines the methods used to act
  41. upon the types defined in `m88k-bcs.h' and `internalcoff.h'.
  42.  
  43.    The Intel i960 processor version of coff is implemented in
  44. `icoff.c'. This file has the same structure as  `m88k-bcs.c', except
  45. that it includes `intel-coff.h' rather than `m88k-bcs.h'.
  46.  
  47. Porting To A New Version of Coff
  48. --------------------------------
  49.  
  50.    The recommended method is to select from the existing
  51. implimentations the version of coff which is most like the one you
  52. want to use, for our purposes, we'll say that i386 coff is the one
  53. you select, and that your coff flavour is called foo. Copy the
  54. `i386coff.c' to `foocoff.c', copy `../include/i386coff.h' to
  55. `../include/foocoff.h' and add the lines to `targets.c' and
  56. `Makefile.in' so that your new back end is used.
  57.  
  58.    Alter the shapes of the structures in `../include/foocoff.h' so
  59. that they match what you need. You will probably also have to add
  60. `#ifdef's to the code in `internalcoff.h' and `coffcode.h' if your
  61. version of coff is too wild.
  62.  
  63.    You can verify that your new BFD backend works quite simply by
  64. building `objdump' from the `binutils' directory, and making sure
  65. that its version of what's going on at your host systems idea
  66. (assuming it has the pretty standard coff dump utility (usually
  67. called `att-dump' or just `dump')) are the same.
  68.  
  69.    Then clean up your code, and send what you've done to Cygnus. Then
  70. your stuff will be in the next release, and you won't have to keep
  71. integrating it.
  72.  
  73. How The Coff Backend Works
  74. --------------------------
  75.  
  76. Bit Twiddling
  77. .............
  78.  
  79.    Each flavour of coff supported in BFD has its own header file
  80. descibing the external layout of the structures. There is also an
  81. internal description of the coff layout (in `internalcoff.h') file
  82. (`'). A major function of the coff backend is swapping the bytes and
  83. twiddling the bits to translate the external form of the structures
  84. into the normal internal form. This is all performed in the
  85. `bfd_swap'_thing_direction routines. Some elements are different
  86. sizes between different versions of coff, it is the duty of the coff
  87. version specific include file to override the definitions of various
  88. packing routines in `coffcode.h'. Eg the size of line number entry in
  89. coff is sometimes 16 bits, and sometimes 32 bits.  `#define'ing
  90. `PUT_LNSZ_LNNO' and `GET_LNSZ_LNNO' will select the correct one. No
  91. doubt, some day someone will find a version of coff which has a
  92. varying field size not catered for at the moment.  To port BFD, that
  93. person will have to add more `#defines'.
  94.  
  95.    Three of the bit twiddling routines are exported to `gdb';
  96. `coff_swap_aux_in', `coff_swap_sym_in' and `coff_swap_linno_in'.
  97. `GDB' reads the symbol table on its own, but uses BFD to fix things up.
  98.  
  99. Symbol Reading
  100. ..............
  101.  
  102.    The simple canonical form for symbols used by BFD is not rich
  103. enough to keep all the information available in a coff symbol table.
  104. The back end gets around this by keeping the original symbol table
  105. around, "behind the sceens".
  106.  
  107.    When a symbol table is requested (through a call to
  108. `bfd_canonicalize_symtab', a request gets through to
  109. `get_normalized_symtab'. This reads the symbol table from the coff
  110. file and swaps all the structures inside into the internal form.  It
  111. also fixes up all the pointers in the table (represented in the file
  112. by offsets from the first symbol in the table) into physical pointers
  113. to elements in the new internal table. This involves some work since
  114. the meanings of fields changes depending upon context; a field that
  115. is a pointer to another structure in the symbol table at one moment
  116. may be the size in bytes of a structure in the next.
  117.  
  118.    Another pass is made over the table. All symbols which mark file
  119. names (`C_FILE' symbols) are modified so that the internal string
  120. points to the value in the auxent (the real filename) rather than the
  121. normal text associated with the symbol (`".file"').
  122.  
  123.    At this time the symbol names are moved around. Coff stores all
  124. symbols less than nine characters long physically within the symbol
  125. table, longer strings are kept at the end of the file in the string
  126. table. This pass moves all strings into memory, and replaces them
  127. with pointers to the strings.
  128.  
  129.    The symbol table is massaged once again, this time to create the
  130. canonical table used by the BFD application. Each symbol is inspected
  131. in turn, and a decision made (using the `sclass' field) about the
  132. various flags to set in the `asymbol' *Note Symbols::. The generated
  133. canonical table shares strings with the hidden internal symbol table.
  134.  
  135.    Any linenumbers are read from the coff file too, and attached to
  136. the symbols which own the functions the linenumbers belong to.
  137.  
  138. Symbol Writing
  139. ..............
  140.  
  141.    Writing a symbol to a coff file which didn't come from a coff file
  142. will lose any debugging information. The `asymbol' structure
  143. remembers the BFD from which was born, and on output the back end
  144. makes sure that the same destination target as source target is
  145. present.
  146.  
  147.    When the symbols have come from a coff file then all the debugging
  148. information is preserved.
  149.  
  150.    Symbol tables are provided for writing to the back end in a vector
  151. of pointers to pointers. This allows applications like the linker to
  152. accumulate and output large symbol tables without having to do too
  153. much byte copying.
  154.  
  155.    The symbol table is not output to a writable BFD until it is
  156. closed.  The order of operations on the canonical symbol table at
  157. that point are:
  158.  
  159. `coff_renumber_symbols'
  160.      This function runs through the provided symbol table and patches
  161.      each symbol marked as a file place holder (`C_FILE') to point to
  162.      the next file place holder in the list. It also marks each
  163.      `offset' field in the list with the offset from the first symbol
  164.      of the current symbol.
  165.  
  166.      Another function of this procedure is to turn the canonical
  167.      value form of BFD into the form used by coff. Internally, BFD
  168.      expects symbol values to be offsets from a section base; so a
  169.      symbol physically at 0x120, but in a section starting at 0x100,
  170.      would have the value 0x20.  Coff expects symbols to contain
  171.      their final value, so symbols have their values changed at this
  172.      point to reflect their sum with their owning section. Note that
  173.      this transformation uses the `output_section' field of the
  174.      `asymbol''s `asection' *Note Sections::.
  175.  
  176. `coff_mangle_symbols'
  177.      This routine runs though the provided symbol table and uses the
  178.      offsets generated by the previous pass and the pointers
  179.      generated when the symbol table was read in to create the
  180.      structured hierachy required by coff. It changes each pointer to
  181.      a symbol to an index into the symbol table of the symbol being
  182.      referenced.
  183.  
  184. `coff_write_symbols'
  185.      This routine runs through the symbol table and patches up the
  186.      symbols from their internal form into the coff way, calls the
  187.      bit twiddlers and writes out the tabel to the file.
  188.  
  189.    The hidden information for an asymbol is:
  190.  
  191.       typedef struct coff_ptr_struct
  192.       {
  193.  
  194.    Remembers the offset from the first symbol in the file for this
  195. symbol. Generated by `coff_renumber_symbols'.
  196.  
  197.         unsigned int offset;
  198.  
  199.    Should the tag field of this symbol be renumbered.  Created by
  200. `coff_pointerize_aux'.
  201.  
  202.         char fix_tag;
  203.  
  204.    Should the endidx field of this symbol be renumbered.  Created by
  205. `coff_pointerize_aux'.
  206.  
  207.         char fix_end;
  208.  
  209.    The container for the symbol structure as read and translated from
  210. the file.
  211.  
  212.         union {
  213.           union internal_auxent auxent;
  214.           struct internal_syment syment;
  215.         } u;
  216.       } combined_entry_type;
  217.  
  218.    Each canonical asymbol really looks like this:
  219.  
  220.       typedef struct coff_symbol_struct
  221.       {
  222.  
  223.    The actual symbol which the rest of BFD works with
  224.  
  225.         asymbol symbol;
  226.  
  227.    A pointer to the hidden information for this symbol
  228.  
  229.         combined_entry_type *native;
  230.  
  231.    A pointer to the linenumber information for this symbol
  232.  
  233.         struct lineno_cache_entry *lineno;
  234.       } coff_symbol_type;
  235.  
  236. Writing Relocations
  237. ...................
  238.  
  239.    To write a relocations, all the back end does is step though the
  240. canonical relocation table, and create an `internal_reloc'. The
  241. symbol index to use is removed from the `offset' field in the symbol
  242. table supplied, the address comes directly from the sum of the
  243. section base address and the relocation offset and the type is dug
  244. directly from the howto field.
  245.  
  246.    Then the `internal_reloc' is swapped into the shape of an
  247. `external_reloc' and written out to disk.
  248.  
  249. Reading Linenumbers
  250. ...................
  251.  
  252.    Createing the linenumber table is done by reading in the entire
  253. coff linenumber table, and creating another table for internal use.
  254.  
  255.    A coff line number table is structured so that each function is
  256. marked as having a line number of 0. Each line within the function is
  257. an offset from the first line in the function. The base of the line
  258. number information for the table is stored in the symbol associated
  259. with the function.
  260.  
  261.    The information is copied from the external to the internal table,
  262. and each symbol which marks a function is marked by pointing its...
  263.  
  264.    **How does this work  **
  265.  
  266. Reading Relocations
  267. ...................
  268.  
  269.    Coff relocations are easily transformed into the internal BFD form
  270. (`arelent').
  271.  
  272.    Reading a coff relocation table is done in the following stages:
  273.  
  274.    * The entire coff relocation table is read into memory.
  275.  
  276.    * Each relocation is processed in turn, first it is swapped from
  277.      the external to the internal form.
  278.  
  279.    * The symbol referenced in the relocation's symbol index is turned
  280.      into a pointer into the canonical symbol table. Note that this
  281.      table is the same as the one returned by a call to
  282.      `bfd_canonicalize_symtab'.  The back end will call the routine
  283.      and save the result if a canonicalization hasn't been done.
  284.  
  285.    * The reloc index is turned into a pointer to a howto structure,
  286.      in a back end specific way. For instance, the 386 and 960 use
  287.      the `r_type' to directly produce an index into a howto table
  288.      vector; the 88k subtracts a number from the `r_type' field and
  289.      creates an addend field.
  290.  
  291.  
  292. 
  293. File: bfd.info,  Node: Index,  Next: Index,  Prev: BFD back end,  Up: Top
  294.  
  295. Function Index
  296. **************
  297.  
  298. * Menu:
  299.  
  300. * BFD_CACHE_MAX_OPEN: File Caching.
  301. * HOWTO: Relocations.
  302. * aout_<size>_machine_type: aout.
  303. * aout_<size>_mkobject: aout.
  304. * aout_<size>_set_arch_mach: aout.
  305. * aout_<size>_some_aout_object_p: aout.
  306. * aout_<size>_swap_exec_header_in: aout.
  307. * aout_<size>_swap_exec_header_out: aout.
  308. * aout_<size>new_section_hook: aout.
  309. * bfd_alloc_size: Opening and Closing.
  310. * bfd_arch_compatible: Architectures.
  311. * bfd_architecture: Architectures.
  312. * bfd_cache_close: File Caching.
  313. * bfd_cache_init: File Caching.
  314. * bfd_cache_lookup: File Caching.
  315. * bfd_cache_lookup_worker: File Caching.
  316. * bfd_canonicalize_symtab: symbol handling functions.
  317. * bfd_check_format: Formats.
  318. * bfd_close: Opening and Closing.
  319. * bfd_core_file_failing_command: Core Files.
  320. * bfd_core_file_failing_signal: Core Files.
  321. * bfd_create: Opening and Closing.
  322. * bfd_fdopenr: Opening and Closing.
  323. * bfd_find_target: bfd_target.
  324. * bfd_format_string: Formats.
  325. * bfd_get_elt_at_index: Archives.
  326. * bfd_get_mtime: BFD front end.
  327. * bfd_get_next_mapent: Archives.
  328. * bfd_get_section_by_name: section prototypes.
  329. * bfd_get_section_contents: section prototypes.
  330. * bfd_get_size: Internal.
  331. * bfd_h_get_size: Internal.
  332. * bfd_h_put_size: Internal.
  333. * bfd_last_cache: File Caching.
  334. * bfd_log2: Internal.
  335. * bfd_make_empty_symbol: symbol handling functions.
  336. * bfd_make_section: section prototypes.
  337. * bfd_map_over_sections: section prototypes.
  338. * bfd_open_file: File Caching.
  339. * bfd_openr: Opening and Closing.
  340. * bfd_openr_next_archived_file: Archives.
  341. * bfd_openw: Opening and Closing.
  342. * bfd_perform_relocation: Relocations.
  343. * bfd_prinable_arch_mach: Architectures.
  344. * bfd_print_symbol_vandf: symbol handling functions.
  345. * bfd_put_size: Internal.
  346. * bfd_scan_arch_mach: Architectures.
  347. * bfd_set_arch_mach: Architectures.
  348. * bfd_set_archive_head: Archives.
  349. * bfd_set_format: Formats.
  350. * bfd_set_section_contents: section prototypes.
  351. * bfd_set_section_flags: section prototypes.
  352. * bfd_set_section_size: section prototypes.
  353. * bfd_set_start_address: BFD front end.
  354. * bfd_set_symtab: symbol handling functions.
  355. * bfd_target: Targets.
  356. * bfd_target_list: bfd_target.
  357. * core_file_matches_executable_p: Core Files.
  358. * get_symtab_upper_bound: symbol handling functions.
  359. * reloc_chain: Relocations.
  360. * reloc_howto_type: Relocations.
  361. * stuff: BFD front end.
  362.  
  363.  
  364. Index
  365. *****
  366.  
  367. * Menu:
  368.  
  369. * BFD: Overview.
  370. * BFD canonical format: Mechanism.
  371. * internal object-file format: Mechanism.
  372. * what is it?: Overview.
  373.  
  374.  
  375.  
  376.    
  377. Tag Table:
  378. Node: Top823
  379. Node: Overview1087
  380. Node: History1992
  381. Node: How It Works2945
  382. Node: What BFD Version 1 Can Do4372
  383. Node: BFD information loss5398
  384. Node: Mechanism8013
  385. Node: BFD front end12349
  386. Node: Memory Usage17366
  387. Node: Sections18586
  388. Node: Section Input19059
  389. Node: Section Output20323
  390. Node: typedef asection21698
  391. Node: section prototypes26487
  392. Node: Symbols30021
  393. Node: Reading Symbols31610
  394. Node: Writing Symbols32567
  395. Node: typedef asymbol34097
  396. Node: symbol handling functions37543
  397. Node: Archives39405
  398. Node: Formats40854
  399. Node: Relocations42963
  400. Node: Core Files54841
  401. Node: Targets55736
  402. Node: bfd_target57455
  403. Node: Architectures66096
  404. Node: Opening and Closing69698
  405. Node: Internal71576
  406. Node: File Caching74036
  407. Node: BFD back end76541
  408. Node: What to Put Where76735
  409. Node: aout76864
  410. Node: coff82571
  411. Node: Index93539
  412.